import book.BookList;

		import user.AdminUser;

         import user.NormalUser;

		import user.User;



		import java.util.Scanner;




		public class Main {

		    public static User login(){

		        System.out.println("请输入您的姓名");

		        Scanner  scanner=new Scanner(System.in);

		        String name= scanner.nextLine();



	        System.out.println("请输入您的身份：1：-》管理员，0:—》普通用户");

		        int choice=scanner.nextInt();

		        if(choice==1){

		        return new AdminUser(name);

		    }

		        else{

	            return new NormalUser(name);

		        }

	        }

		    public static void main(String[] args) {

		            //开始整合

	        BookList  booklist=new BookList();//准备图书


        //登录

		        User user=login();//相当于向上转型

		        user.menu();

		        int choice = user.menu();//动态绑定

		        user.doOperation(choice,booklist);

		    }

}

		package book;




	public class Book {

	    private String name;

		    private String author;

	    private int price;

		    private  String type;

	    private boolean isBorrowed;


    public Book(String name, String author, int price, String type) {

		        this.name = name;

	        this.author = author;

		        this.price = price;

	        this.type = type;

	    }




        return name;

	    }



   public void setName(String name) {

		        this.name = name;

	    }



    public String getAuthor() {

        return author;

		    }



		    public void setAuthor(String author) {

		        this.author = author;

    }



	    public int getPrice() {

	       return price;

		    }



		    public void setPrice(int price) {

		        this.price = price;

		    }



		    public String getType() {

	        return type;

	    }



	    public void setType(String type) {

	        this.type = type;

	    }



	    public boolean isBorrowed() {

		        return isBorrowed;

	    }



	    public void setBorrowed(boolean borrowed) {

		        isBorrowed = borrowed;

		    }



	    @Override

	    public String toString() {

        return "Book{" +

	                "name='" + name + '\'' +

		                ", author='" + author + '\'' +

		                ", price=" + price +

	             ", type='" + type + '\'' +

	71	                ", isBorrowed=" + isBorrowed +

	72	                '}';

	73	    }

	74	}
 +49 2022.6.24/2022.6.24/src/book/BookList.java 0 → 100644 
	1	package book;

	2	



	10	public class BookList {

	11	

	12	    private Book[]  books=new Book[20];

	13	    private int usedSize;//实时记录当前books这个数组当中有多少本书

	14	

	15	

	16	    public BookList(){

	17	         books[0]=new Book("白夜行","东野圭吾",60,"悬疑推理");

	18	         books[1]=new Book("嫌疑人X的献身","东野圭吾",80,"悬疑推理");

	19	         books[2]=new Book("彷徨之刃","东野圭吾",120,"悬疑推理");

	20	         usedSize=3;

	21	

	22	    }

	23	    //根据书的位置，拿到这本书

	24	    public Book getBook(int pos){

	25	        return books[pos];

	26	    }

	27	    /*

	28	    * 新增书，POS是要放的位置

	29	    * book是你要放的书

	30	    * */

	31	    public void setBooks( int pos , Book  book){

	32	        books[pos]=book;

	33	    }

	34	    /*

	35	    *

	36	    * 实时获取当前的书的个数

	37	    *

	38	    * */

	39	    public int getUsedSize(){

	40	        return usedSize;

	41	    }

	42	    /*

	43	    * 实时修改当前书架上的书的个数

	44	    *

	45	    * */

	46	    public  void   setUsedSize(int size){

	47	        usedSize=size;

	48	    }

	49	}
 +17 2022.6.24/2022.6.24/src/operation/AddOperation.java 0 → 100644 
	1	package operation;

	2	

	3	import book.BookList;

	4	


	12	public class AddOperation  implements IOperation {

	13	    @Override

	14	    public void work(BookList booklist) {

	15	        System.out.println("新增图书");

	16	    }

	17	}

	1	package operation;

	2	

	3	import book.BookList;

	4	


	12	public class BorrowOperation implements IOperation{

	13	    @Override

	14	    public void work(BookList booklist) {

	15	        System.out.println("借阅图书");

	16	    }

	17	}
 +17 2022.6.24/2022.6.24/src/operation/DelOperation.java 0 → 100644 
	1	package operation;

	2	

	3	import book.BookList;

	4	



	12	public class DelOperation implements IOperation{

	13	    @Override

	14	    public void work(BookList booklist) {

	15	        System.out.println("删除图书");

	16	    }

	17	}
 +17 2022.6.24/2022.6.24/src/operation/ExitOperation.java 0 → 100644 
	1	package operation;

	2	

	3	import book.BookList;

	4	

	5
	12	public class ExitOperation implements  IOperation{

	13	    @Override

	14	    public void work(BookList booklist) {

	15	        System.out.println("退出系统");

	16	    }

	17	}

	1	package operation;

	2	

	3	import book.BookList;

	4	

	5

	12	public class FindOperation implements IOperation {

	13	    @Override

	14	    public void work(BookList booklist) {

	15	        System.out.println("查找图书");

	16	    }

	17	}

	1	package operation;

	2	

	3	import book.Book;

	4	import book.BookList;

	5	

	6



	13	public interface IOperation {

	14	    void work(BookList  booklist);

	15	}

	1	package operation;

	2	

	3	import book.BookList;

	4	

	5

	12	public class ReturnOperation implements IOperation{

	13	    ;

	14	

	15	    @Override

	16	    public void work(BookList booklist) {

	17	        System.out.println("归还图书");

	18	    }

	19	}

	1	package operation;

	2	

	3	import book.BookList;

	4	



	12	public class ShowOperation implements IOperation{

	13	    @Override

	14	    public void work(BookList booklist) {

	15	        System.out.println("显示图书");

	16	    }

	17	}
 +43 2022.6.24/2022.6.24/src/user/AdminUser.java 0 → 100644 
	1	package user;

	2	

	3	import operation.*;

	4	

	5	import java.util.Scanner;

	6	



	14	public class AdminUser extends User{

	15	    public AdminUser(String name) {

	16	        super(name);

	17	        this.iOperations = new IOperation[]{

	18	                new ExitOperation(),

	19	                new FindOperation(),

	20	                new AddOperation(),

	21	                new DelOperation(),

	22	                new ShowOperation(),

	23	

	24	

	25	

	26	        };

	27	    }

	28	    public int  menu(){

	29	        System.out.println("hello"+this.name+"欢迎您来到图书小练习！🎉");

	30	        System.out.println("1.查找图书！");

	31	        System.out.println("2.新增图书！");

	32	        System.out.println("3.删除图书！");

	33	        System.out.println("4.显示图书！");

	34	        System.out.println("0.退出系统！");

	35	        System.out.println("请输入您的操作😁");

	36	        Scanner scanner=new Scanner(System.in);

	37	        int choice = scanner.nextInt();

	38	        return  choice;

	39	

	40	

	41	    }

	42	

	43	}

	1	package user;

	2	

	3	import operation.*;

	4	

	5	import java.util.Scanner;

	6	



	14	public class NormalUser extends User {

	15	    public NormalUser(String name) {

	16	        super(name);

	17	        this.iOperations = new IOperation[]{

	18	                new ExitOperation(),

	19	                new FindOperation(),

	20	                new BorrowOperation(),

	21	                new ReturnOperation(),

	22	

	23	

	24	

	25	        };

	26	    }

	27	    public int  menu(){

	28	        System.out.println("hello"+this.name+"欢迎您来到图书小练习！🎉");

	29	        System.out.println("1.查找图书！");

	30	        System.out.println("2.借阅图书！");

	31	        System.out.println("3.归还图书！");

	32	        System.out.println("0.退出系统！");

	33	        System.out.println("请输入您的操作😁");

	34	        Scanner  scanner=new Scanner(System.in);

	35	        int choice = scanner.nextInt();

	36	        return  choice;

	37	

	38	

	39	    }

	40	}
 +27 2022.6.24/2022.6.24/src/user/User.java 0 → 100644 
	1	package user;

	2	

	3	import book.BookList;

	4	import operation.IOperation;

	5	



		abstract    public class User {

		    protected String name;//用户名



	    public User(String name) {

		        this.name = name;

		    }

		    public abstract int  menu();

	protected IOperation[] iOperations  ;//

	    public void doOperation(int choice, BookList  booklist){

		        this.iOperations[choice].work(booklist);


	    }







		}
package operation;



		import book.Book;

	import book.BookList;


		import java.util.Scanner;







	public class DelOperation implements IOperation{

	    @Override

	    public void work(BookList booklist) {

        System.out.println("删除图书");

	19	        Scanner scanner=new Scanner(System.in);

	20	        System.out.println("请输入删除图书的名字：");

	21	        String  name= scanner.nextLine();

	22	        int currentSize= booklist.getUsedSize();

	23	        int index=-1;

	24	        int i =0;

	25	        for (; i <currentSize ; i++) {

	26	            Book  book=booklist.getBook(i);

	27	            if(book.getName().equals(name)){

	28	                index=i;

	29	                break;

	30	            }

	31	        }

	32	

	33	        if(i>=currentSize){

	34	            System.out.println("没有找到这本书");

	35	            return;

	36	        }

	37	            for(int j=index;j<currentSize ;j++){

	38	                Book book=booklist.getBook(i+1);

	39	                booklist.setBooks(i,book);

	40	            }

	41	            booklist.setBooks( currentSize-1,null);//删除了书籍，进行了移动，然后将最后的置为空，不会有内存泄漏

	42	            booklist.setUsedSize(currentSize-1);

	43	        System.out.println("删除成功");

16	44	    }

17	45
	}